<?php
session_start();
class Login{

	private $conexion;
	private $resource;
	private $sql;
	public static $queries;
	private static $_singleton;

	public static function getInstance(){
		if (is_null (self::$_singleton)) {
			self::$_singleton = new Login();
		}

		return self::$_singleton;
	}
	private function __construct(){}
	function __destruct(){
	}
	
	public static function GetLoggedUser(){
		return $_SESSION['logged'];
	}
	public static function ValidateLogin(){
		if(!$_SESSION['logged'] )
			header('location: index.php');

	}
	
	public function LogOut(){
		$_SESSION['logged'] = null;
		header('location: index.php');
	}	


	public function ValidateUser($username, $password){
		$db = DataBase::getInstance();
		$res = $db->execute("select * from user where username = '". $username ."' and password = '". $password."'");
		if($db->has_rows()){
			$_SESSION['logged'] = @mysql_fetch_array($res, MYSQL_ASSOC);
			return true;
		}
		return false;
	}




}

?>